/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "ipc_request.h"

#include "net_manager_log.h"
#ifdef EXT_SUPPORT_SYSVPN
#include "networkvpn_client.h"
#endif
#include "securec.h"

#ifdef EXT_SUPPORT_SYSVPN
using namespace std;
using namespace OHOS::NetManagerStandard;
#endif

int32_t NotifyConnectStage(char *stage, int32_t state)
{
#ifdef EXT_SUPPORT_SYSVPN
    return NetworkVpnClient::GetInstance().NotifyConnectStage(std::string(stage), state);
#else
    return 0;
#endif
}

int32_t GetSysVpnCertUri(enum IpsecVpnCertType type, uint8_t *certUrl, uint32_t srcSize)
{
#ifdef EXT_SUPPORT_SYSVPN
    std::string uri;
    int32_t ret = NetworkVpnClient::GetInstance().GetSysVpnCertUri(type, uri);
    if (ret != 0) {
        return 0;
    }
    uint32_t size = strlen(uri.c_str());
    size = size < srcSize ? size : srcSize;
    NET_LOG_I("ret:%d type:%d uri: %s size:%d", ret, type, uri.c_str(), size);
    (void)memset_s(certUrl, srcSize, 0, srcSize);
    memcpy_s(certUrl, srcSize, (uint8_t *)(uri.c_str()), size);
    return size;
#else
    return 0;
#endif
}
